package com.example.checkout.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
public class User implements Serializable {
    private static final long serialVersionUID = 322886380149549978L;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id", example = "1")
    private Integer user_id;

    /**
     * 用户名
     */
    @ApiModelProperty(value = "用户名", example = "海带")
    private String name;

    /**
     * 借阅的书籍
     */
    @ApiModelProperty(value = "借阅的书籍", example = "海带的春天")
    private String borrowedBooks;

    /**
     * 借阅上限
     */
    @ApiModelProperty(value = "借阅上限", example = "3")
    private Integer checkout;

    /**
     * 钱
     */
    @ApiModelProperty(value = "钱", example = "100.0")
    private Double money;

    /**
     * 银行卡
     */
    @ApiModelProperty(value = "银行卡", example = "123456")
    private String card;

    /**
     * 借书时间
     */
    @ApiModelProperty(value = "借书时间", example = "2025-03-13 13:48:35")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime borrowTime;

    /**
     * 还书时间
     */
    @ApiModelProperty(value = "约定还书时间", example = "2025-03-15 13:48:35")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime returnTime;

    /**
     * 权限枚举
     */
    @ApiModelProperty(value = "权限枚举", example = "TEACHER/Student")
    private UserPermission permission;

    // 新增方法：根据权限获取借阅上限
    public int getCheckoutLimit() {
        if (permission == UserPermission.TEACHER) {
            return 5;
        } else {
            return 3;
        }
    }
}